<?php

class Db_Tables2_BLogsAction
{
	var $action_id;
	var $related_id;
	var $contents;
	
	function __construct() {
		$this->dealers_db = Zend_Registry::get("dealers_db");
	}
	
	function addRecord()
	{
		$result = FALSE;
		
		if($this->action_id && $this->contents)
		{
			$set = array(
				"action_id" => $this->action_id,
				"contents" => $this->contents,
				"emp_id" => $_SESSION['identity']['userid'],
				"ctime" => date("Y-m-d H:i:s")
			);
			
			if($this->related_id)
			{
				$set['related_id'] = $this->related_id;
			}
			
			if($this->dealers_db->insert("b_logs_action", $set))
			{
				$result = TRUE;
			}
		}
		
		return $result;
	}
	
	function GetLogs($action_id_array, $related_id)
	{
		$result = array();
		
		if(is_array($action_id_array) && !empty($action_id_array) && $related_id)
		{
			$select = $this->dealers_db->select();
			$select->from("b_logs_action as l", array("related_id", "contents", "ctime"));
			$select->joinLeft("b_dict_action as a", "a.action_id=l.action_id", array("action_name"));
			$select->joinLeft("hxb_db.auth_emp as e", "e.id=l.emp_id", array("realName"));
			$select->where("l.action_id IN (?)", $action_id_array);
			$select->where("l.related_id = ?", $related_id);
			$select->order("l.lpid DESC");
			$result = $this->dealers_db->fetchAll($select);
		}
		
		return $result;
	}
}